package no.ntnu.fp.model;

import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.text.DecimalFormat;

import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.Timer;
import no.ntnu.fp.watch.co.Database;
import no.ntnu.fp.watch.gui.WellListModel;
import no.ntnu.fp.watch.gui.WellTableModel;
import no.ntnu.fp.watch.gui.platformPanel;

public class Watch extends JFrame
{
	private Platform platform;
	private Database database;
	private platformPanel platformPanel;
	private WellListModel wellListModel;
	
	private PropertyChangeSupport pcs;
	
	private Toolkit toolkit;
	public static boolean isMaster;
	
	static Dimension screenSize;
	
	public static Dimension getScreenSize(){
		return screenSize;
	}
	
	
	public final static String wellPath = "C:\\Wells\\";
	
	public Watch(Platform platform, boolean master)
	{
		isMaster = master;
		
		toolkit = Toolkit.getDefaultToolkit();
		screenSize = toolkit.getScreenSize();
		
		this.platform = platform;
		this.platform.setCurrentWell(platform.getWell(0));
		
		//det boolske argumentet forteller platformPanel om det er MASTER eller vanlig WATCH
		this.platformPanel = new platformPanel(platform, Watch.isMaster);
		this.setJMenuBar(platformPanel.getJMenuBar());
		this.wellListModel =  new WellListModel(platform, null);
		this.platformPanel.setWellListModel(wellListModel);
		
		
		pcs = new PropertyChangeSupport(this);
	}
	
	public void setPlatformPanel(platformPanel p){
		this.platformPanel = p;
	}
	
	public platformPanel getPlatformPanel(){
		return this.platformPanel;
	}
	


	public void setWellListModel(WellListModel wellListModel) {
		this.wellListModel = wellListModel;
	}

	public WellListModel getWellListModel() {
		return wellListModel;
	}
	
	public static String roundDouble(double number, int decimals){
		String format = "0.";
		
		for (int i = 0; i < decimals; i++) {
			format += "0";
		}
		
		DecimalFormat df = new DecimalFormat(format);
		df.setMinimumFractionDigits(2);
		df.setMinimumIntegerDigits(1);
		
		return df.format(number);
	}

	
}